﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Tong;
using Tong.ThisSiteUse;
public partial class aspnet_admin_bock_collect_CX_Collert_Show_State1 : System.Web.UI.Page
{
    public TongUse TextData = new TongUse();
    public SiteTong TextThisSite = new SiteTong();
    protected void Page_Load(object sender, EventArgs e)
    {
        LinkButton2.Attributes.Add("onclick", "allid(); switchBar('');sADiv('');document.getElementById('LoadingDiv').style.display='compact';");
        LinkButton3.Attributes.Add("onclick", "return confirm('您确定要删除此页面所有文章吗?');");
        BindData();

    }

    //看看是不是要删除数据
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");

            l.Attributes.Add("onclick", "javascript:return " +

            "confirm('您确定要删除 " +

            DataBinder.Eval(e.Row.DataItem, "CX_Collect_Name").ToString().Replace("\r\n","").Replace("\r","").Replace("\n","") + "吗?')");

        }

    }

    protected void BindData()
    {
        DataTable TempTab = new DataTable();
        TempTab = TextData.SqlataSet("SELECT * FROM [CX_Collect] where CX_Collect_Sitate=1 order by CX_Collect_id   desc").Tables[0];
        GridView1.DataSource = TempTab.DefaultView;
        GridView1.DataBind();
    }


    /// <summary>
    /// 添加到新闻事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void KeyWord_edit_Click(object sender, EventArgs e)
    {
        string RedirID = ((LinkButton)sender).CommandArgument.ToString();

        if (RedirID != "")
        {
            //执行SQL

            
            try
            {
                ///查询TAB
                DataTable CollertSTab = new DataTable();

                CollertSTab = TextData.SqlataSet("select * from [CX_Collect] where CX_Collect_id = " + RedirID).Tables[0];
                
                string Csql ="";
                Csql = "update  [CX_NEWS] Set ";
                Csql = Csql + " CX_NEWS_Class_id = " + CollertSTab.Rows[0]["CX_NEWS_Class_id"].ToString() + ","+
               "CX_NEWS_Creater = '" + CollertSTab.Rows[0]["CX_Collect_Class_Creater"].ToString().Trim() + "',CX_NEWS_From = '" + CollertSTab.Rows[0]["CX_Collect_FormURL"].ToString().Trim() + "',CX_NEWS_Top=" +
                "'" + 0 + "',CX_NEWS_Pic='" + 0 + "',CX_NEWS_Pic_Url= '',CX_NEWS_Cont='" + CollertSTab.Rows[0]["CX_Collect_Contont"].ToString().Trim().Replace("'", "") + "',CX_NEWS_Sort=" + 0 + ", Cx_keyWord_Name='" + CollertSTab.Rows[0]["Cx_keyWord_Name"].ToString().Trim().Replace("'", "") + "'";
                Csql += " where CX_NEWS_Name='" + CollertSTab.Rows[0]["CX_Collect_Name"].ToString() + "'";


                TextData.SqlDataSave(Csql);
                TextThisSite.AddNewCX_loginState(Request.Cookies["admin"].Value, "CX_Collert_Show_State1.aspx", "更新采集数据" + CollertSTab.Rows[0]["CX_Collect_Name"].ToString() + "");
                tt.Text = "更新" + CollertSTab.Rows[0]["CX_Collect_Name"].ToString() + "成功";


                //CollertSTab.Clear();
                CollertSTab.Dispose();
                BindData();
                
            }
            catch(Exception ex)
            {
                tt.Text = ex.Message;
            }
        }

    }

    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void delcc(object sender, EventArgs e)
    {

        string RedirID = ((LinkButton)sender).CommandArgument.ToString();
        if (RedirID != "")
        {
            try
            {
                TextData.SqlDataSave("delete [CX_Collect] where CX_Collect_id = " + RedirID);
                tt.Text = "";
                tt.Text = "删除 信息成功" ;
                TextThisSite.AddNewCX_loginState(Request.Cookies["admin"].Value, "CX_Collert_Show_State1.aspx", "删除采集数据" + RedirID + "");
                BindData();
            }
            catch
            {
                tt.Text = "";
                tt.Text = "删除  时出现错误　操作没有完成 ";
            }
        }
    
    }

    /// <summary>
    /// 用于设定
    /// </summary>
    /// <param name="sid"></param>
    /// <returns></returns>
    public string GetColumn(string sid)
    {

        try
        {
            return TextData.SqlataSet("select top 1 * from [CX_NEWS_Class] where CX_NEWS_Class_id=" + sid).Tables[0].Rows[0]["CX_NEWS_Class_Name"].ToString();
        }
        catch
        {
            return "没有设定,将出现不可知的错误";
        }
    }

    /// <summary>
    /// 加入所有文章
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        string[] AllidS = HiddenField1.Value.Split(',');
       // 查询TAB
        DataTable CollertSTab = new DataTable();
        string RedirID = "";
        tt.Text = "";
        for (int i = 0; i < AllidS.Length; i++)
        {

            RedirID = AllidS[i].ToString();
            if (RedirID.Trim() != "")
            {
                CollertSTab = TextData.SqlataSet("select * from [CX_Collect] where CX_Collect_id = " + RedirID).Tables[0];

                string CsqlX = "";
                CsqlX = "update  [CX_NEWS] Set ";
                CsqlX = CsqlX + " CX_NEWS_Class_id = " + CollertSTab.Rows[0]["CX_NEWS_Class_id"].ToString() + "," +
               "CX_NEWS_Creater = '" + CollertSTab.Rows[0]["CX_Collect_Class_Creater"].ToString().Trim() + "',CX_NEWS_From = '" + CollertSTab.Rows[0]["CX_Collect_FormURL"].ToString().Trim() + "',CX_NEWS_Top=" +
                "'" + 0 + "',CX_NEWS_Pic='" + 0 + "',CX_NEWS_Pic_Url= '',CX_NEWS_Cont='" + CollertSTab.Rows[0]["CX_Collect_Contont"].ToString().Trim().Replace("'", "") + "',CX_NEWS_Sort=" + 0 + ", Cx_keyWord_Name='" + CollertSTab.Rows[0]["Cx_keyWord_Name"].ToString().Trim().Replace("'", "") + "'";
                CsqlX += " where CX_NEWS_Name='" + CollertSTab.Rows[0]["CX_Collect_Name"].ToString() + "'";
                TextData.SqlDataSave(CsqlX);

                tt.Text += "更新" + CollertSTab.Rows[0]["CX_Collect_Name"].ToString() + "成功<br/>";
                TextThisSite.AddNewCX_loginState(Request.Cookies["admin"].Value, "CX_Collert_Show_State1.aspx", "更新采集数据" + CollertSTab.Rows[0]["CX_Collect_Name"].ToString() + "");
                System.Threading.Thread.Sleep(100);

                

               
            }
          
            
        }
        
        CollertSTab.Clear();
        CollertSTab.Dispose();
        BindData();
        HiddenField1.Value = "";
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        //设定删除页面所有的文章 SQL
        string DellAllSql = "";
        if (HiddenField1.Value != "")
        {
            DellAllSql = "Delete [CX_Collect] where CX_Collect_id in(" + HiddenField1.Value + ")";
           // Response.Write(DellAllSql);
            TextData.SqlDataSave(DellAllSql);
            tt.Text = "已成功删除本页所有文章";
            BindData();
        }
    }
    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void a11(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
    }
}